<%@ page language="java" import="java.util.*,entity.*,dao.*,dao.impl.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
TopicDao topicDao = new TopicDaoImpl();
ReplyDao replyDao = new ReplyDaoImpl();
UserDao userDao = new UserDaoImpl();
BoardDao boardDao = new BoardDaoImpl();
int boardId = Integer.parseInt(request.getParameter("boardId"));
int topicId = Integer.parseInt(request.getParameter("topicId"));
int p  = Integer.parseInt(request.getParameter("page"));
Board board = boardDao.findBoard(boardId);
Topic topic = topicDao.findTopic(topicId);
User topicUser =userDao.findUser(topic.getUid());
List listReply = replyDao.findListReply(p,topicId);

int prep =p;
int nextp = p;
	if(listReply.size() == 10){
		nextp =p +1;
	}
	if(p>1){
	prep = p-1;
	}
 %>

<!DOCTYPE html>
<html>
    <head>
    	<base href="<%=basePath%>">
        <title>看帖</title>
        <style>
            *{margin:0;padding:0;}
            .divhead{
            margin-top:50px;
            height:50px; 
            text-align: center;
            line-height:50px; 
            }
            .divhead>p{
            text-shadow:#FF0000 0 0 10px;
            color:white;
            font-size:60px
            }
            .div2{
                margin-top:30px;
                text-align:center;
               
            }
            .div2>p{
                background-color: gray;
            }
            .div3{
	            width:800px;
                color:white;
                text-align: left;
                margin-left: 70px;
                margin-top: 10px;
	        }
            a:link{
                color:salmon;
            }
            a:visited{
                color:bisque;
            }
            a:hover{
                color:red;
            }
            .button{
                font-size: 16px;
                border-radius: 6px;
                width:10%;
                box-shadow: 10px;
                margin-top: 10px;
            }
            .div4{
                background-color: rgb(134, 134, 209);
                margin-top: 10px;
            }
            .div4>p{
                
                margin-left: 70px;
            }
            table{
                border: solid 1px white;
                margin:auto;
                color: black;
                width: 1000px;
            }
            img{
                width:80px;
                height:80px;
            }
            tr td:nth-child(2){
                margin-left:150px;
            }
            .div5>p{
                color:white;
            }
            </style>
    </head>
    <body background="img/background.jpg">
        <div class="divhead">
            <p>北京科技大学天津学院BBS</p>
        </div>
        <div class ="div2">
            <%if(session.getAttribute("user")==null){ %>
           <%if(session.getAttribute("user")==null){ %>
            <p>您尚未<a href="login.jsp" target ="_blank">登录</a> | <a href="reg.jsp" target ="_blank">注册</a> 
            <%}else{            
            	User loginUser =(User)session.getAttribute("user"); 
            %>
            	您好：<%= loginUser.getUName() %></p>
             <%} %> 
            <%}else{            
            	User loginUser =(User)session.getAttribute("user"); 
            %>
            	您好：<%= loginUser.getUName() %></p>
             <%} %>
        </div>
        
        <div class="div3">&gt;&gt;&gt;<a href="index.jsp" target ="_blank">论坛首页</a>&gt;&gt;
        	<a href="list.jsp?page=1&boardId=<%=boardId %>"><%=board.getBoardName() %></a>
            <p><a href="reply.jsp?topicId=<%=topicId%>&boardId=<%= boardId%>&boardName=<%=board.getBoardName()%>">回复帖子</a>
            
            	<a href="post.jsp?boardId=<%=boardId%>&boardName=<%=board.getBoardName()%>">发表话题</a>
            </p> 
        </div>
        <div class="div4">
            <p>本页主题：<%= topic.getTitle() %></p>
        </div>
        <div>
			<%if(p==1){ %>
                <table>
                    <tr>
                        <td>
	                        <%= topicUser.getUName() %><br/>
	                        <img src="img/<%=topicUser.getHead() %>"/>
	                        <br/>
	                        	注册：<%=topicUser.getRegTime() %>
                        </td>
                        <td><p><%= topic.getTitle() %></p>
                            <p></p>
                            <p><%= topic.getContent() %></p>
                            <p>发表：[<%= topic.getPublishTime() %>]&nbsp; 最后修改：[ <%=topic.getModifyTime() %>]</p>
                        </td>
                    </tr>
                </table> 
                <%
                }
                 %>
                 <!-- 回复 -->
                 <%
                 for(int i=0;i<listReply.size();i++){
                 	Reply reply=(Reply)listReply.get(i);
                 	User replyUser =(User)userDao.findUser(reply.getUid());
                  %>
                <table>   
                    <tr>
                        <td><%= replyUser.getUName() %><br/>
                        <img src="img/<%=replyUser.getHead()%>"/>
                        <br/>注册：<%=topicUser.getRegTime() %></td>
                        <td><p><%=reply.getTitle() %></p>
                            <p></p>
                            <p><%=reply.getContent() %></p>
                            <p>发表：[<%= reply.getPublishTime() %>] 最后修改： [<%= reply.getModifyTime() %>] 
                            	<a href="">【删除】</a>
                            	<a href="">【修改】</a></p>
                        </td>
                    </tr>
                </table>
                <%
                } %>
                <p class="p">
                <a href="detail.jsp?page=<%=prep %>&boardId=<%= boardId%>&topicId=<%= topicId%>">上一页</a>|
                <a href="detail.jsp?page=<%= nextp%>&boardId=<%= boardId%>&topicId=<%= topicId%>">下一页</a>
                </p>
        </div>
        

    </body>
</html>